/*
** File name:		window_menu_user_delete_group.c
** Brief: 
** COPYRIGHT(C) gkt 2021 
** ------------------------------------------------------- 
** Module Information: 
** 
** Revision History -------------------------------------- 
** ------------------------------------------------------- 
**	Date 		Version		Action				Author   
** ------------------------------------------------------- 
**	2021-1-19 	1.0			Created				liwenjie   
** 
*/ 

/* Includes -----------------------------------------------------*/
#include "gkt_user.h"
#include "window_common.h"

/* Global Variables ---------------------------------------------*/
/* Macro --------------------------------------------------------*/
enum {
	WIDGET_ID_USER_DELETE_GROUP_TITLE = 0,	
	WIDGET_ID_USER_DELETE_GROUP_LIST,
	WIDGET_ID_MAX
};

static const gkt_widget_list_item_s sc_window_user_delete_group_auth_list_items[] = {
#if (GKT_USER_GUEST_MAXNUMS > 0)
	GKT_WIDGET_LIST_STATIC_ITEM(WINDOW_TEXT_ID_guest_user, GKT_USER_AUTH_GUEST),
#endif
	GKT_WIDGET_LIST_STATIC_ITEM(WINDOW_TEXT_ID_normal_user, GKT_USER_AUTH_NORMAL),
#if defined(GKT_CONFIG_WINDOW_ALLOW_DELETE_ADMIN) && GKT_CONFIG_WINDOW_ALLOW_DELETE_ADMIN
	GKT_WIDGET_LIST_STATIC_ITEM(WINDOW_TEXT_ID_admin_user, GKT_USER_AUTH_ADMIN)
#endif
};
static const gkt_widget_list_attr_s sc_window_user_delete_group_auth_list_attr = 
	GKT_WIDGET_LIST_STATIC_ATTR(WINDOW_WIDGET_NORMAL_HEIGHT, 
			sizeof(sc_window_user_delete_group_auth_list_items) / sizeof(gkt_widget_list_item_s), 
			sc_window_user_delete_group_auth_list_items);

GKT_WINDOW_WIDGET_DESCS_DEFINE(user_delete_group) = {
	[WIDGET_ID_USER_DELETE_GROUP_TITLE] = GKT_WIDGET_LABEL_DESC(
			GKT_WIDGET_F_ALIGN_MIDDLE | GKT_WIDGET_F_ALIGN_CENTER | GKT_WIDGET_F_TITLE_MARK,
			WINDOW_FONT_NORMAL_SIZE, 
			WINDOW_TITLE_FG_COLOR, WINDOW_TITLE_BG_COLOR,
			0, 0, 
			WINDOW_WIDGET_DEFAULT_WIDTH, WINDOW_WIDGET_NORMAL_HEIGHT,
			WINDOW_TEXT_ID_group_delete),
	[WIDGET_ID_USER_DELETE_GROUP_LIST] = GKT_WIDGET_LIST_DESC(
			GKT_WIDGET_F_FOCUSABLE | GKT_WIDGET_F_ALIGN_MIDDLE,
			WINDOW_FONT_NORMAL_SIZE, 
			WINDOW_DEFAULT_FG_COLOR, WINDOW_DEFAULT_BG_COLOR, 
			0, WINDOW_WIDGET_NORMAL_HEIGHT, 
			WINDOW_WIDGET_DEFAULT_WIDTH, WINDOW_WIDGET_NORMAL_HEIGHT * (WINDOW_NORMAL_ROWS - 1),
			&sc_window_user_delete_group_auth_list_attr),						
};

struct _user_delete_group {
	uint32_t	auth;
};
static struct _user_delete_group s_window_user_delete_group;

/* Extern Functions ---------------------------------------------*/
/* Static Functions ---------------------------------------------*/

static int window_user_delete_group_event_handler(uint32_t major_type, 
				uint32_t minor_type, uint32_t widget_id, 
				uint32_t data)
{
	gkt_user_amount_s  amount;
	int retval = GKT_EVENT_HANDLE_CONTINUE;
	
	switch (major_type) {
		case GKT_EVENT_WINDOW:
			if (GKT_WINDOW_ACTIVE == minor_type)
				window_common_mask_except_updn_cancel_ok();
			break;
		case GKT_EVENT_WIDGET:
			if (GKT_WIDGET_EVENT_CLICK == minor_type) {
				s_window_user_delete_group.auth = sc_window_user_delete_group_auth_list_items[data].data;

				amount.used_nums = 0;
				gkt_user_get_amount(&amount, s_window_user_delete_group.auth, GKT_USER_TYPE_MAX);
				if (amount.used_nums)
					gkt_window_show(WINDOW_ID_user_delete_group_type, s_window_user_delete_group.auth);
				else {
					window_dialog_show_big_prompt(WINDOW_DIALOG_HINT_NORMAL,
						gc_window_delete_auth_user_text_ids[s_window_user_delete_group.auth],
						WINDOW_TEXT_ID_no_user,
						WINDOW_VOICE_COMBINED_ID(user_not_exist));
				}

				retval = GKT_EVENT_HANDLE_COMPLETE;
			}
			break;
		default:
			break;
	}

	return retval;
}

/* Functions ----------------------------------------------------*/
GKT_WINDOW_DESC_DEFINE(user_delete_group);

/* end */
